import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mirac
 * Date: 2025-11-26
 * Time: 22:16
 */
public class MinStack {

    private Stack<Integer> stack1; //用来装压进来的数
    private Stack<Integer> stack2; //用来装最小的数

    public MinStack() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void push(int val) {
        this.stack1.push(val);
        //如果stack2为空，直接放入，否则进行比较
        if (stack2.isEmpty()) {
            stack2.push(val);
        }else {
            int ans = stack2.peek();
            if (ans >= val) {
                stack2.push(val);
            }
        }
    }

    public void pop() {
        int ans = stack1.pop();
        if (ans == stack2.peek()) {
            stack2.pop();
        }
    }

    public int top() {
        return stack1.peek();
    }

    public int getMin() {
        return stack2.peek();
    }
}
